<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Connecting to PostgreSQL databases</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />

 </head>
 <body class="docs"><div class="navbar navbar-fixed-top">
  <div class="navbar-inner clearfix">
    <ul class="nav" style="width: 100%">
      <li style="float: left;"><a href="ref.pdo-pgsql.html">« PostgreSQL (PDO)</a></li>
      <li style="float: right;"><a href="pdo.pgsqlcopyfromarray.html">PDO::pgsqlCopyFromArray »</a></li>
    </ul>
  </div>
</div>
<div id="breadcrumbs" class="clearfix">
  <ul class="breadcrumbs-container">
    <li><a href="index.html">PHP Manual</a></li>
    <li><a href="ref.pdo-pgsql.html">PostgreSQL (PDO)</a></li>
    <li>Connecting to PostgreSQL databases</li>
  </ul>
</div>
<div id="layout">
  <div id="layout-content"><div id="ref.pdo-pgsql.connection" class="refentry">
   <div class="refnamediv">
    <h1 class="refname">PDO_PGSQL DSN</h1>
    <p class="verinfo">(PHP 5 &gt;= 5.1.0, PHP 7, PECL PDO_PGSQL &gt;= 0.1.0)</p><p class="refpurpose"><span class="refname">PDO_PGSQL DSN</span> &mdash; <span class="dc-title">Connecting to PostgreSQL databases</span></p>

   </div>

   <div class="refsect1 description" id="refsect1-ref.pdo-pgsql.connection-description">
    <h3 class="title">说明</h3>
    <p class="para">
     The PDO_PGSQL Data Source Name (DSN) is composed of the following elements, delimited by spaces or semicolons:
     <dl>
      
       <dt>
DSN prefix</dt>

       <dd>

        <p class="para">
        The DSN prefix is <strong class="userinput"><code>pgsql:</code></strong>.
        </p>
       </dd>

      
      
       <dt>
<code class="literal">host</code></dt>

       <dd>

        <p class="para">
         The hostname on which the database server resides.
        </p>
       </dd>

      
      
       <dt>
<code class="literal">port</code></dt>

       <dd>

        <p class="para">
         The port on which the database server is running.
        </p>
       </dd>

      
      
       <dt>
<code class="literal">dbname</code></dt>

       <dd>

        <p class="para">
         The name of the database.
        </p>
       </dd>

      
      
       <dt>
<code class="literal">user</code></dt>

       <dd>

        <p class="para">
         The name of the user for the connection. If you specify the user name
         in the DSN, PDO ignores the value of the user name argument in the
         PDO constructor.
        </p>
       </dd>

      
      
       <dt>
<code class="literal">password</code></dt>

       <dd>

        <p class="para">
         The password of the user for the connection. If you specify the
         password in the DSN, PDO ignores the value of the password argument
         in the PDO constructor.
        </p>
       </dd>

      
      
       <dt>
<code class="literal">sslmode</code></dt>

       <dd>

        <p class="para">
         The SSL mode. Supported values and their meaning are listed in the
         <a href="http://www.postgresql.org/docs/current/interactive/" class="link external">&raquo;&nbsp;PostgreSQL Documentation</a>.
        </p>
       </dd>

      

     </dl>

     <blockquote class="note"><p><strong class="note">注意</strong>: 
      <span class="simpara">
       All semicolons in the DSN string are replaced by spaces, because PostgreSQL
       expects this format. This implies that semicolons in any of the components
       (e.g. <code class="literal">password</code> or <code class="literal">dbname</code>) are not
       supported.
      </span>
     </p></blockquote>
    </p>
   </div>

   <div class="refsect1 examples" id="refsect1-ref.pdo-pgsql.connection-examples">
    <h3 class="title">范例</h3>
    <p class="para">
     <div class="example" id="example-1106">
      <p><strong>示例 #1 PDO_PGSQL DSN examples</strong></p>
      <div class="example-contents"><p>
       The following example shows a PDO_PGSQL DSN for connecting to
       a PostgreSQL database:
       <div class="example-contents">
<div class="cdata"><pre>
pgsql:host=localhost;port=5432;dbname=testdb;user=bruce;password=mypass
</pre></div>
       </div>

      </p></div>
      <div class="example-contents"><p>
       The following example shows a PDO_PGSQL DSN for connecting to
       a PostgreSQL database via unix socket <var class="filename">/tmp/.s.PGSQL.5432</var>:
       <div class="example-contents">
<div class="cdata"><pre>
pgsql:host=/tmp;port=5432;dbname=testdb;user=bruce;password=mypass
</pre></div>
       </div>

      </p></div>
     </div>
    </p>
   </div>

  </div></div></div></body></html>